package top.fyukina.fymil.internal.cmds;

import org.dom4j.Element;
import top.fyukina.fymil.elements.CmdBlock;
import top.fyukina.fymil.elements.Environment;

public class While implements Command {
    @Override
    public String registerName() {
        return "while";
    }
    @Override
    public void run(Element tag, Environment env) {
        //TODO 实现break标签
        Element cond = tag.element("cond");
        boolean bl = true;
        if (cond == null) {
            while (true) {
                new CmdBlock(tag, env.var()).execute(env);
                //实现break标签
            }
        } else {
            bl = env.reg().boolParser.parse(cond, env);
            while (bl) {
                new CmdBlock(tag, env.var()).execute(env);
                bl = env.reg().boolParser.parse(cond, env);
            }
        }
    }
}